package com.atguigu.gmall.payment.process.factory;

import com.atguigu.gmall.payment.process.PayHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author: atguigu
 * @create: 2023-03-22 11:26
 */
@Component
public class PaymentFactory {

    /**
     * 当前项目中所有支付方式实现类对象
     * Map key:对象bean Id
     * Map val:支付对象
     */
    @Autowired
    private Map<String, PayHandler> payHandlerMap;


    /**
     * 根据支付方式 查询支付对象
     *
     * @param payType
     * @return
     */
    public PayHandler getPayHandler(String payType) {
        PayHandler payHandler = payHandlerMap.get(payType);
        if (payHandler == null) {
            throw new RuntimeException("当前支付方式不支持");
        }
        return payHandler;
    }
}
